package  
{
	/**
	 * ...
	 * @author UWGameDevClub
	 */
	public class Rooms 
	{
		public var Bedroom:Room;
		public var LivingRoom:Room;
		public var KitchenRoom:Room;
		
		private var _boozeLeft:Number = 3;
		private var _boozeFound:Number = 0x000;
		
		public function Rooms()
		{
			createBedroom();
			createLivingRoom();
			createKitchen();
		}
		
		private function createKitchen():void {
			KitchenRoom = new Room(Art.Kitchen);
			
			var livingroomDoor:IteamArea = new IteamArea(Items.KITCHENTOLIVINGROOM, 50, 446, 0);
			var kitchenBooze1:Item = new Item(Art.Rum, Items.BOOZE);
			var kitchenBooze2:Item = new Item(Art.Vodka, Items.BOOZE);
			
			KitchenRoom.add(livingroomDoor, 0, 165);
			KitchenRoom.add(kitchenBooze1, 860, 0);
			KitchenRoom.add(kitchenBooze2, 614, 259);
			
			livingroomDoor.interact = function():void { Main.main.setRoom(LivingRoom); }
			kitchenBooze1.interact = function():void {
				KitchenRoom.remove(kitchenBooze1);
				_boozeLeft--;
				_boozeFound += 0x010;
				Main.main.showReceipt(_boozeFound);
				if (_boozeLeft == 2) Main.main.playScript(Scripts.FindBooze);
				if (_boozeLeft == 1) Main.main.playScript(Scripts.FindMoreBooze);
				if (_boozeLeft == 0) Main.main.playScript(Scripts.FindAllBooze);
			}
			kitchenBooze2.interact = function():void {
				KitchenRoom.remove(kitchenBooze2);
				_boozeLeft--;
				_boozeFound += 0x100;
				Main.main.showReceipt(_boozeFound);
				if (_boozeLeft == 2) Main.main.playScript(Scripts.FindBooze);
				if (_boozeLeft == 1) Main.main.playScript(Scripts.FindMoreBooze);
				if (_boozeLeft == 0) Main.main.playScript(Scripts.FindAllBooze);
			}
		}
		
		private function createLivingRoom():void {
			LivingRoom = new Room(Art.LivingRoom);
			LivingRoom.x = Main.main.stage.stageWidth - LivingRoom.width;
			LivingRoom.y = Main.main.stage.stageHeight - LivingRoom.height;
			
			var bedroomDoor:IteamArea = new IteamArea(Items.LIVINGTOBEDROOM, 33, 693, 1);
			var kitchenDoor:IteamArea = new IteamArea(Items.LIVINGTOKITCHEN, 160, 385, 0);
			var receipt:Item = new Item(Art.Receipt, Items.RECEIPT);
			var livingroomBooze:Item = new Item(Art.Beer, Items.BOOZE);
			var tvstand:Item = new Item(Art.TVStand, Items.TVSTAND);
			var plant:Item = new Item(Art.Plant, Items.PLANT);
			
			LivingRoom.add(bedroomDoor, 1167, 0);
			LivingRoom.add(kitchenDoor, 0, 0);
			LivingRoom.add(receipt, 580, 455);
			LivingRoom.add(livingroomBooze, 870, 260);
			LivingRoom.add(tvstand, 337, 192, Scripts.TVStand);
			LivingRoom.add(plant, 668, 0, Scripts.Plant);
			
			bedroomDoor.interact = function():void { Main.main.playScript(Scripts.Gate) }
			kitchenDoor.interact = function():void { Main.main.playScript(Scripts.Gate) }
			livingroomBooze.interact = function():void { Main.main.playScript(Scripts.Bottle); }
			receipt.interact = function():void {
				Main.main.playScript(Scripts.FindReceipt);
				LivingRoom.remove(receipt);
				bedroomDoor.interact = function():void { Main.main.setRoom(Bedroom); }
				kitchenDoor.interact = function():void { Main.main.setRoom(KitchenRoom); }
				livingroomBooze.interact = function():void {
					LivingRoom.remove(livingroomBooze);
					_boozeLeft--;
					_boozeFound += 0x001;
					Main.main.showReceipt(_boozeFound);
					if (_boozeLeft == 2) Main.main.playScript(Scripts.FindBooze);
					if (_boozeLeft == 1) Main.main.playScript(Scripts.FindMoreBooze);
					if (_boozeLeft == 0) Main.main.playScript(Scripts.FindAllBooze);
				}
			}
		}
		
		private function createBedroom( ):void
		{
			Bedroom = new Room(Art.Bedroom);
			Bedroom.x = -75;
			Bedroom.y = -175;
			var teddy:FrameItem = new FrameItem( [Art.TeddyBear, Art.TeddyHat], Items.TEDDY );
			var hat:Item = new Item( Art.Hat, Items.HAT );
			var necklace:Item = new Item( Art.Necklace, Items.NECKlACE );
			var sunshine:Item = new Item(Art.Doll, Items.SUNSHINE);
			var door:IteamArea = new IteamArea( Items.BEDROOMDOOR, 115, 550, 1 );
			var bed:Item = new Item(Art.JennyBed, Items.JENNYBED);
			var ball:Item = new Item(Art.Ball, Items.BALL);
			var magnifyingGlass:Item = new Item( Art.maglass, Items.MAGNIFYINGGLASS );
			var books:Item = new Item( Art.Books, Items.BOOKS );
			var pillow:Item = new Item( Art.pillow, Items.PILLOW );
			var rope:Item = new Item( Art.jumprope, Items.JUMPROPE );
			var apple:Item = new Item( Art.Apple, Items.APPLE );
			Bedroom.add(apple, 555, 368, Scripts.AppleDescription );
			Bedroom.add(rope, 390, 378, Scripts.RopeDescription );
			Bedroom.add(pillow, 340, 346, Scripts.PillowDescription );
			Bedroom.add(books, 535, 285, Scripts.BooksDescription );
			Bedroom.add(magnifyingGlass, 436, 300, Scripts.MagnifyingGlass );
			Bedroom.add(ball, 347, 286, Scripts.BallDescription );
			Bedroom.add(door, 870, 32, Scripts.StayInRoom );
			Bedroom.add(necklace, 34, 534);
			Bedroom.add(bed, 0, 314);
			Bedroom.add(hat, 545, 200);
			Bedroom.add(sunshine, 570, 525, Scripts.SunshineDescription);
			Bedroom.add(teddy, 400, 475, Scripts.BearDescription);
			bed.mouseEnabled = false;
			
			necklace.interact = function():void {
				Main.main.playScript( Scripts.ItWasBear );
				necklace.interact = function():void {
					Main.main.playScript(Scripts.NecklaceDescription);
				}
				
				hat.interact = function( ):void
				{
					Main.main.playScript( Scripts.NiceTry );
					hat.interact = function():void {
						Main.main.playScript(Scripts.HatDescription);
					}
					hat.select = function():void {
						Main.main.playScript(Scripts.HatSelection);
						hat.select = null;
					}
					teddy.combine = function( o:Item ):void {
						if ( o.getName() == Items.HAT )  { 
							Bedroom.remove(o);
							teddy.frame(1);
							teddy.combine = null;
							Main.main.playScript( Scripts.AceDetective );
							door.interact = function():void { Main.main.setRoom(LivingRoom); }
						}
					}
				}
			}
		}
	}

}